//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// Cross-Platform shared memory for multi-processes
///</describe>
/// <date>2024/4/14</date>
///***********************************************************************
#ifndef SHAREMEM_H
#define SHAREMEM_H

#include <string>
#include "ModuleLoader/ModuleConfig.h"

namespace SystemTool
{
    class CLASS_ITEM ShareMem
    {
    public:
        // Construct the obj
        ShareMem();

        // Destruct the obj
        ~ShareMem();

    private:
        // Copy construct
        ShareMem(const ShareMem& other) = delete;

        // Assignment
        ShareMem& operator=(const ShareMem& other) = delete;

    public:
        // Create a share memory
        void Create(std::string strShareMemName,
                    int iMemSize,
                    int iAccessMode,
                    const void *pStartAddr = 0,
                    bool bIsServer = true);

        // Read from the share memory
        bool Read(char *pData, int iReadSize);

        // Write to the share memory
        bool Write(const char *pData, int iWriteSize);

        // Destroy the share memory
        void Destroy();

    private:
        // Poco share memory
        void* m_pShareMem;
    };
}

#endif // SHAREMEM_H
